﻿
@{
    ViewData["Title"] = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>列表</h2>
<div id="articleListDiv" style="margin-bottom:20px"></div>
<button type="button" onclick="exportExcel1()" class="btn">导出Excel1</button>
<a href="/Article/ExportExcel2" class="btn">导出Excel2</a>

<script type="text/javascript">
    $(function(){
        loadList();
    });

	function loadList(){
		$.ajax({
            url:'/Article/GetArticleList',
            type:'post',
            dataType:'html',//这里返回的是分部视图，不是json串，所以dataType类型不为json
            async:true,
            beforeSend: function () {
                $('#articleListDiv').html('');
            },
            success:function(data){
                $('#articleListDiv').html(data);
            },
            error:function(ex){
                alert('加载失败！');
            }
        });
	}

    function exportExcel1(){
        $.ajax({
            url:'/Article/ExportExcel1',
            type:'post',
            dataType:'json',
            async:true,
            success:function(data){
                if(data.code=='success'){
                    //window.location.href='/excel/20190325195219495.xlsx'。即可下载
                    window.location.href=data.msg;
                }
                else{
                    alert(data.msg);
                }
            },
            error:function(ex){
                alert('导出Excel失败！');
            }
        });
    }
</script>

